//
//  STBaseTableViewCell.m
//  赛拓
//
//  Created by 王磊 on 7/28/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STBaseTableViewCell.h"
#import "STSettingTableViewCell.h"
#import "STGoodsTableViewCell.h"
#import "STGoodsTableViewHeaderCell.h"
#import "STSellerTableViewCell.h"
#import "STOrderTableViewCell.h"
#import "STSellerBean.h"
#import "STApplicationFormTableViewCell.h"
#import "STApplicationFormHeaderTableViewCell.h"
#import "STCommodityBean.h"
@interface STBaseTableViewCell()

@property (nonatomic ,assign) HZSCellBottomLineType bottomLineType;

@property (nonatomic ,strong) UIImageView *bottomLine;
@end
@implementation STBaseTableViewCell


- (void)updateData:(id)data {
    
    
    
}
- (void)updateData:(id)data andAccessoryViewData:(id)accData {
    
    
}
+ (instancetype)instanceWithCellIdentifier:(STCellType )cellIdentifier andBottomLineType:(HZSCellBottomLineType)bottomLineType {
    return [[self alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"%ld",cellIdentifier] andBottomLineType:bottomLineType];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier andBottomLineType:(HZSCellBottomLineType)bottomLineType {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _bottomLineType = bottomLineType;
        
        [self configSubViews];
    }
    return self;
}
- (UIImageView *)bottomLine {
    if (!_bottomLine) {
        
        _bottomLine = [[UIImageView alloc]init];
        
        [self addSubview:_bottomLine];
    }
    return _bottomLine;
}
- (void)configSubViews {
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    switch (self.bottomLineType) {
        case HZSCellBottomLineTypeNone:
            //            self.bottomLine.backgroundColor = HZS_ClearColor;
            break;
        case HZSCellBottomLineTypeSingLineWhite:
            //            self.bottomLine.backgroundColor = HZS_WhiteColor;
            break;
        case HZSCellBottomLineTypeSingLineBlack:
            //            self.bottomLine.backgroundColor = HZS_BlackColor;
            break;
            
        case HZSCellBottomLineTypeSpecialLineWhite:
            //            self.bottomLine.image = [UIImage imageNamed:HZS_White_Line];
            break;
        case HZSCellBottomLineTypeTaperedline:
            
            //            self.bottomLine.image = [UIImage imageNamed:HZS_Tapered_Line];
            //        case HZSCellBottomLineTypeSpecialLineWhite:
            //
            //            imageView.image = [UIImage imageNamed:HZS_White_Line];
            break;
        case HZSCellBottomLineTypeLineBlack:
            
            break;
            
        case HZSCellBottomLineTypeCommodityLine:
            //
            self.bottomLine.backgroundColor = ST_999999_COLOR;
            
        default:
            NSLog(@"Unknown cell bottom line type ");
            break;
    }
    //    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
}
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.bottomLine.frame = CGRectMake(0, self.k_height - 0.5, self.k_width, 0.5);
}


// cell 工厂
+ (STBaseTableViewCell *)baseTableViewCell:(STCellType)cellType forIndexPath:(NSIndexPath *)indexPath {
    
    switch (cellType) {
        case STCellTypeSetting:
            
            return [STSettingTableViewCell instanceWithCellIdentifier:cellType andBottomLineType:HZSCellBottomLineTypeNone];
            
        case STCellTypeGoods:
            
            return [STGoodsTableViewCell instanceWithCellIdentifier:cellType andBottomLineType:HZSCellBottomLineTypeNone];
            
        case STCellTypeGoodsHeader:
            
            return [STGoodsTableViewHeaderCell instanceWithCellIdentifier:cellType andBottomLineType:HZSCellBottomLineTypeNone];
            
        case STCellTypeSellerList:
            
            return [STSellerTableViewCell instanceWithCellIdentifier:cellType andBottomLineType:HZSCellBottomLineTypeCommodityLine];
        case STCellTypeOrder:
            
            return [STOrderTableViewCell instanceWithCellIdentifier:cellType andBottomLineType:HZSCellBottomLineTypeCommodityLine];
        case STCellTypeApplicationForm:
            
            return [STApplicationFormTableViewCell instanceWithCellIdentifier:cellType andBottomLineType:HZSCellBottomLineTypeNone];
        case STCellTypeMaterial:
            
            return [STApplicationFormHeaderTableViewCell instanceWithCellIdentifier:cellType andBottomLineType:HZSCellBottomLineTypeCommodityLine];
        default:
            
            break;
    }
    return nil;
}

// cell 高度工厂
+ (CGFloat)heightForCell:(STCellType)cellType withData:(id)data forIndexPath:(NSIndexPath *)indexPath {
    switch (cellType) {
        case STCellTypeSetting:
            
            return 100 * ST_RATE;
        case STCellTypeGoods:
            
            return 80 * ST_RATE;
            
        case STCellTypeGoodsHeader:
            
            return 150 * ST_RATE;
        case STCellTypeSellerList:
        {
            STSellerBean *seller = data;
            
            return seller.commodities.count > 3 ? 220 * ST_RATE + 60 * ST_RATE + 280 * ST_RATE * 3 : 220 * ST_RATE + 60 * ST_RATE + 280 * ST_RATE * seller.commodities.count;
        }
        case STCellTypeOrder:
            
            return 340 * ST_RATE;
        case STCellTypeApplicationForm:
            
            return 150 + 20 * ST_RATE ;
            // 个人资料头部
        case STCellTypeMaterial:
            
            return 90 * ST_RATE;
        default:
            break;
    }
    return 0;
}

@end
